package com.lc.zpyh.ui.activity.mine;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.lc.widget.layout.SettingBar;
import com.lc.zpyh.R;
import com.lc.zpyh.app.AppActivity;
import com.lc.zpyh.http.glide.GlideApp;
import com.lc.zpyh.manager.CacheDataManager;
import com.lc.zpyh.manager.ThreadPoolManager;
import com.lc.zpyh.ui.activity.AboutActivity;
import com.lc.zpyh.widget.UIHelper;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SystemActivity extends AppActivity {
    @BindView(R.id.sb_setting_people)
    SettingBar sbSettingPeople;
    @BindView(R.id.sb_setting_address)
    SettingBar sbSettingAddress;
    @BindView(R.id.sb_setting_safe)
    SettingBar sbSettingSafe;
    @BindView(R.id.sb_setting_cache)
    SettingBar sbSettingCache;
    @BindView(R.id.sb_setting_about)
    SettingBar sbSettingAbout;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_system;
    }

    @Override
    protected void initView() {
//        sbSettingCache.setRightText(CacheDataManager.getTotalCacheSize(this));
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        sbSettingCache.setRightText(CacheDataManager.getTotalCacheSize(this));
    }

    @OnClick({R.id.sb_setting_people, R.id.sb_setting_address, R.id.sb_setting_safe, R.id.sb_setting_cache, R.id.sb_setting_about,R.id.sb_setting_xieyi,R.id.sb_setting_tiaokuan})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.sb_setting_xieyi:
                startActivity(new Intent(this, XieYiActivity.class).putExtra("title","用户协议"));
                break;
            case R.id.sb_setting_tiaokuan:
                startActivity(new Intent(this,XieYiActivity.class).putExtra("title","隐私条款"));
                break;
            case R.id.sb_setting_people:
                UIHelper.startActivity(this, PersonalCenterActivity.class);
                break;
            case R.id.sb_setting_address:
                UIHelper.startActivity(this, MineAddressManagementActivity.class);
                break;
            case R.id.sb_setting_safe:
                UIHelper.startActivity(this, AccountSafetActivity.class);
                break;
            case R.id.sb_setting_cache:
                GlideApp.get(getActivity()).clearMemory();
                ThreadPoolManager.getInstance().execute(() -> {
                    CacheDataManager.clearAllCache(this);
                    // 清除本地缓存（必须在子线程）
                    GlideApp.get(getActivity()).clearDiskCache();
                    post(() -> {
                        // 重新获取应用缓存大小
                        sbSettingCache.setRightText(CacheDataManager.getTotalCacheSize(getActivity()));
                    });
                });
                break;
            case R.id.sb_setting_about:
                UIHelper.startActivity(this, AboutActivity.class);
                break;
        }
    }
}
